The Registry Access component provides access to the registry keys on a local or remote machine. Using this component, you can retrieve, set, add, delete, and copy registry keys and named values.
For security reasons, only methods that do not modify the registry (such as the Get and GetExpand methods) will work by default. To enable the other methods of the Registry Access component, you must do one of the following: grant administrator permissions to the .asp file that calls the component, set the Discretionary Access Control List for the .asp file to allow access by administrators only, or grant administrator permissions to the IUSR_machinename account.
You can set the permissions of the .asp file by right-clicking on the file in Windows NT® Explorer or by using the Cacls.exe utility from the command line. For more information, see the Windows NT® product documentation.
If your disk is formatted using Windows NT® file system (NTFS), you can also enable these methods by setting the .asp file's permissions to File Administrator. However, if your disk is formatted using the FAT file system, you cannot set security options for individual files.
Another option if you are using an NTFS volume, is to set the Discretionary Access Control List (DACL) to administrators only for the .asp file that calls the Registry Access component. Then if a machine running Windows NT® or Windows® 95 uses Microsoft® Internet Explorer to connect to the .asp file, the server will automatically trigger the Windows NT® Challenge Response (NT C/R) protocol. Note that because NT C/R is currently supported only by Microsoft® Internet Explorer, this method will not allow access to clients using other browsers.
Note This component is not officially supported by Microsoft Corporation. Peer support is available on the Active Server Pages mailing list or on the microsoft.public.inetserver.iis.activeserverpages newsgroup.
To subscribe to the Active Server Pages mailing list, send e-mail to listserv@listserv.msn.com with
subscribe ActiveServerPages [firstname lastname]
in the body of the message, and then follow the directions carefully. (Firstname and lastname are optional.)
You can reach the newsgroup through msnews.microsoft.com and other NNTP servers.
File Names
Registry.dll | The Registry Access component. |
Set oVar = Server.CreateObject("IISSample.Registry")
None.
CopyKey | Copies a registry key. |
DeleteKey | Deletes a key and all its subkeys and named values from the registry. |
DeleteValue | Deletes a named value from a registry key. |
ExpandString | Expands a string by replacing environment variables, such as %PATH%, with their values. |
Get | Retrieves a named value from a registry key. |
GetExpand | Retrieves a named value from a registry key, expanding any embedded environment variables. |
KeyExists | Returns a BOOLEAN that indicates whether the specified key exists in the registry. |
Set | Sets a named value in a registry key. |
SetExpand | Sets a named value in a registry key as data type REG_EXPAND_SZ. |
ValueType | Returns the data type of a registry value. |
A registry key is a node in the registry that can contain both subkeys and data entries called named values. Subkeys are formed by extending the parent key. For example, HKLM\Software\MyCompany is a subkey of HKLM\Software.
A named value consists of a key name followed by a value name. For example, to specify the value MyValue stored under the key HKLM\Software\MyCompany, you would use the following string:
HKLM\Software\MyCompany\MyValue
Default values are named values whose name is a zero-length string. For example, the default value of the key HKLM\Software\MyCompany would be:
HKLM\Software\MyCompany\
A registry key must be a subkey of one of a group of predefined keys. You can use either the complete or shorthand version of the following predefined key names:
In addition, you can specify that a registry key is located on a remote machine by prefixing the key with the machine name. For example:
\\RemoteMachine\HKEY_LOCAL_MACHINE\Software\Microsoft\Java VM\Classpath
Note You cannot use the Registry Access component to access subkeys of HKEY_CURRENT_USER. The component runs in the system context, which does not contain user-specific information.
Because the Registry Access component uses the registry cache, changes in the registry are not immediately written to the disk. These changes are typically written to the disk either by the registry's lazy flusher or when the system shuts down.
However, you can write a registry change to the disk immediately by using the Flush parameter. The Flush parameter is a Boolean value that specifies whether changes should be immediately written to the registry. For more information about the Flush parameter, see the individual method references.
If a method fails (for example, if you tried to retrieve the value of a nonexistent key), you can trap the resulting error in your ASP script. For example, in Visual Basic® Scripting Edition (VBScript) you can use the On Error statement to handle errors.
<% Set Reg = Server.CreateObject("IISSample.Registry") %> JavaClassPath: <%= Reg.Get("HKLM\Software\Microsoft\Java VM\Classpath") %><BR>
Note The examples in this document use Microsoft® Visual Basic® Scripting Edition (VBScript) as the primary scripting language. However, ASP scripts can be written in any supported scripting language, such as Microsoft® JScript™.